<?
require_once('functions.php');

function GetPaymentMethods()
{
        $conn = GetConnection();
        return $conn->query('SELECT * FROM PaymentMethods');
}

function GetMethod($id, $table)
{
            $conn = GetConnection();
        $sql = "SELECT * FROM $table WHERE id=$id";
        $results = $conn->query($sql);
        //echo $sql;
        $pay = $results->fetch_assoc();
        $conn->close();
        return $pay;
}
function GetPaymentMethodDetail($id)
{
            $conn = GetConnection();
        $sql = "SELECT * FROM PaymentMethods WHERE id=$id";
        $results = $conn->query($sql);
        //echo $sql;
        $pay = $results->fetch_assoc();
        $conn->close();
        return $pay;
}
function GetInfoType($id)
{
        $conn = GetConnection();
        $sql = "SELECT * FROM ContactInfoType WHERE id=$id";
        $results = $conn->query($sql);
        //echo $sql;
        $row = $results->fetch_assoc();
        $conn->close();
        return $row;
}
function Save($row)
{
        $conn = GetConnection();
        $row2 = EscapeRow($row, $conn);
        $sql =  "UPDATE PaymentMethods "
                .       "Set  CardType='$row2[CardType]', CardNumber='$row2[CardNumber]', NameOnCard='$row2[NameOnCard]', ExpDate='$row2[ExpDate]', SecCode='$row2[SecCode]',                                                                                                                                                                                                                                                           Customers_id='$row2[Customers_id]', created_at='$row2[created_at]', updated_at='$row2[updated_at]'"
                .       "WHERE id=$row2[id] ";
        $results = $conn->query($sql);
        echo $sql;
        $error = $conn->error;
        $conn->close();
        
        return $error == '' ? true : array('SQL Error' => $error);
}
function Create($row)
{
        $conn = GetConnection();
        $sql =  "INSERT INTO PaymentMethods (Customers_id, CardType, CardNumber, NameOnCard, ExpDate, SecCode) VALUES ('$row[Customers_id]', '$row[CardType]', '$row[CardNumber]', '$row[NameOnCard]', '$row[ExpDate]', '$row[SecCode]') ";        
                $results = $conn->query($sql);
        echo $sql;
        $error = $conn->error;
        $conn->close();
}
function Delete($row)
{
        $conn = GetConnection();
        $sql =  "DELETE FROM PaymentMethods "
                .       "WHERE id=$row[id]";
        $result1 = $conn->query($sql);
    //echo $sql;
        $error = $conn->error;
        echo $error;
    $conn->close();     
        return $error == '' ? true : array('SQL Error' => $error);
}
